package cn.ym.mall.service.impl;

import cn.ym.mall.dao.ComplaintsDao;
import cn.ym.mall.dao.impl.ComplaintsDaoImpl;
import cn.ym.mall.entity.Complaints;
import cn.ym.mall.service.ComplaintsService;
import cn.ym.mall.utils.DruidUtils;
import cn.ym.mall.vo.Page;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * 赵金明
 * 2022/8/12
 */
public class ComplaintsServiceImpl implements ComplaintsService {
    private ComplaintsDao complaintsDao = new ComplaintsDaoImpl();
    /**
     * 新增投诉
     *
     * @param complaints 新增的投诉
     * @return
     * @throws SQLException
     */
    @Override
    public boolean addComplaints(Complaints complaints) throws SQLException {
        return complaintsDao.addComplaints(complaints) == 1;
    }

    /**
     * 通过投诉id查询投诉信息
     *
     * @param tsid
     * @return
     * @throws SQLException
     */
    @Override
    public Complaints getComplaintsByTid(Integer tsid) throws SQLException {
        Complaints complaints=null;
        Connection connection = null;
        try {
            connection = DruidUtils.getConnection();
            complaints = complaintsDao.getComplaintsByTid(tsid);
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            DruidUtils.close();
        }
        return complaints;
    }

    /**
     * 分页查询所有投诉
     *
     * @param pageNo
     * @param pageSize
     * @return
     * @throws SQLException
     */
    @Override
    public Page<Complaints> getPageComplaints(Integer pageNo, Integer pageSize) throws SQLException {
        Page<Complaints> page = new Page<Complaints>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        page.setCount((int)complaintsDao.getComplaintsCount());
        page.setList(complaintsDao.getPageComplaints(pageNo,pageSize));
        return page;
    }
}
